﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SystemCenter.Orchestrator.Integration;
using System.Diagnostics;

namespace EventLogIntegrationPack
{
    [Activity ("Write EventLog Entry")]
    public class WriteEventLogEntry
    {
        private string _EventLogSource;
        private string _EventLogName;
        private string _Message;
        private int _EventID;
        private EventLogEntryType _EventType; 
        [ActivityInput]
        public string EventLogSource
        {
            set { _EventLogSource = value; }
        }
        [ActivityInput]
        public string EventLogName
        {
            set { _EventLogName = value; }
        }
        [ActivityInput]
        public int EventID
        {
            set { _EventID = value; }
        }
        [ActivityInput]
        public string Message
        {
            set { _Message = value; }
        }
        [ActivityInput]
        public EventLogEntryType EventType
        {
            set { _EventType = value; }
        }
        /// <summary>
        /// An Activity that writes event log entries in a spezific event log on the local machine.
        /// </summary>
        [ActivityMethod]
        public void Write()
        {
            if (!EventLog.SourceExists(_EventLogSource))
                EventLog.CreateEventSource(_EventLogSource, _EventLogName);
            EventLog.WriteEntry(_EventLogSource,_Message,_EventType,_EventID);

        }
    }
}
